#include <reg167.h>

#include "gestion_timer3.h"


#define PERIODE_CLOCK_TIMER (PRESCALER/FREQUENCE_C167)
#define	NB_CYCLES ( (int) (PERIODE_VOULUE/1000.0/PERIODE_CLOCK_TIMER))





void init_T3 (void)
	{
	int ordre_prescaler=0;
	int buffer_prescaler=PRESCALER;
	bit mon_bit=0;
	
	while(!mon_bit)
		{
		buffer_prescaler = buffer_prescaler >> 1;
		mon_bit=!(buffer_prescaler&&1);
		ordre_prescaler++;
		}
	ordre_prescaler -= 3;

	T3CON |= ordre_prescaler;		  	//T3I = 110b T3M = 000b
	T3CON |= (1<<7);					//T3UD = 1
	T3 =  NB_CYCLES;
	}

void init_interruption(void)
	{
	IEN = 1;
	T3IC = 64;
	T3IC += 4;
	}

void interruption_timer_T3(void) interrupt 0x23
	{
			T3 = NB_CYCLES;
			T3_HANDLER;
	}